package com.unsins.web;

import com.unsins.core.session.SessionManagerUtils;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;


/**
 * Created by IntelliJ IDEA.
 * User: odpsoft
 * Date: 2009-4-21
 * Time: 17:06:16
 */
public class SessionController extends AbstractController {
    private static final Logger logger = Logger.getLogger(SessionController.class);
    private SessionManagerUtils sessionManager;

    public void setSessionManager(SessionManagerUtils session) {
        sessionManager = session;
    }

    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        Object sessionAttribute =
                sessionManager.getSessionAttribute(httpServletRequest);
        Map<String,Object> model = new HashMap<String,Object>();
        model.put("sessionvalue", sessionAttribute);
        ModelAndView mav = new ModelAndView("session", model);

        logger.info(sessionAttribute == null ? "session is null" : sessionAttribute);
        return mav;
    }
}
